package com.sdgakj.repository;

import com.sdgakj.entity.FeedMsg;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.List;

public class FeedMsgDaoImpl {

	@PersistenceContext
	private EntityManager em;

	/**
	 * 时间倒叙消息
	 * 
	 * @param customerId
	 * @param pageSize
	 * @return
	 */
	public List<FeedMsg> findTimeline(Long customerId, Integer pageSize) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT \n");
		sql.append(" t1.* \n");
		sql.append("FROM \n");
		sql.append("  sht_feed_msg t1 \n");
		sql.append("WHERE 1 = 1 \n");
//		sql.append("  AND t1.deltag = '0' \n");
		if(customerId != null) {
			sql.append("  AND t1.customer_id = :customerId \n");
		}
		sql.append("ORDER BY t1.id DESC \n");
		sql.append("LIMIT 0, :rows \n");

        Query q = em.createNativeQuery(sql.toString(), FeedMsg.class);
        if(customerId != null) {
        	q.setParameter("customerId", customerId);
		}
		q.setParameter("rows", pageSize);
		return q.getResultList();
	}
	
}
